#include <bits/stdc++.h>
using namespace std;


int main() {
    int T;
    scanf("%d", &T);
    while(T--){
        int D, I;
        scanf("%d%d", &D, &I);

        int b = 1;
        while(b <= (1<<D)-1){
            if(I%2) {b*=2; I = (I+1)/2;}
            else {b = b*2+1; I/=2;}
        }
        printf("%d\n", b/2);
    }
    return 0;
}